<?php

namespace AliPay;

/**
 *
 * @author lovebing <i@lovebing.org>
 */
class DirectPay extends Base {

    private $api = 'create_direct_pay_by_user';

    /**
     * 
     * @param AccountInfo $account
     * @param PayParams $params
     * @throws Exception
     */
    public function __construct(AccountInfo $account, PayParams $params) {
        $params->tradeNo = trim($params->tradeNo);
        $params->subject = trim($params->subject);

        if (!in_array(gettype($params->totalFee), array('double', 'integer'))) {
            throw new Exception('Param Type Error', -1);
        }
        if ($params->tradeNo == '' || $params->subject == '' || $params->totalFee <= 0) {
            throw new Exception('Param Value Error', -2);
        }

        $this->md5Key = $account->md5Key;
        $this->businessParams = array(
            'out_trade_no' => $params->tradeNo,
            'subject' => $params->subject,
            'payment_type' => 1,
            'seller_id' => $account->partner,
            'total_fee' => $params->totalFee
        );
        $this->mainParams['partner'] = $account->partner;
        $this->mainParams['service'] = $this->api;
        $this->mainParams['return_url'] = $params->returnUrl;
        $this->mainParams['notify_url'] = $params->notifyUrl;
    }

}

?>
